<html>

    <?php
    echo $this->render("/common/header.phtml");
    ?>

    <script>        
        
        function updateType(typeId){
            var baseUrl = <?php echo '"' . $this->update . '"' ?>   
            var txt =  document.getElementById('type'+typeId);
            var typeName = txt.value;
            var a = baseUrl+"?id="+typeId+"&name="+typeName;
            ajax.get(a,null,function(f){
                alert(f);
            },null);            
        }

        function deleteType(typeId){
            var baseUrl = <?php echo '"' . $this->delete . '"' ?>   
            var a = baseUrl+"?id="+typeId;               
            ajax.get(a,null,function(f){
                alert(f);
            },null);            
        }
        
        function addType(){
            var baseUrl = <?php echo '"' . $this->add . '"' ?>   
            var txt =  document.getElementById('txtInput');
            var name = txt.value;
            var a = baseUrl+"?name="+name;               
            ajax.get(a,null,function(f){
                alert(f);
            },null);            
        }

    </script>

    <body>
        <?php
        echo $this->render("/common/topMenu.phtml");
        ?>
    <center>
        <div id="tbType" class="tbType" >
            <div id="inputNew">
                <input id="txtInput" type="text" value = "" name="name" text=""/> 
                <input type="submit" value="Add" onclick="addType()"/>                
            </div>
            <table border="0px" id="gradient-style">
               <?php
                echo "<tr>
                        <th>Type Id</th>
                        <th>Type Name</th>
                        <th>Update</th>
                        <th>Delete</th>
                      </tr>";
                foreach ($this->type as $data) {

                    echo '  <tr> ';
                    echo '      <td> ' . $data['id'] . '</td>';
                    echo '      <td> ' .
                    '<input type="text" id="type' . $data['id'] . '"  value = "' . $data['name'] . '"/>'
                    . '</td>';
                    echo '      <td> <input type="submit" onclick="updateType(' . $data['id'] . ') " value="Update" /></td>';
                    echo '      <td> <input type="submit" onclick="deleteType(' . $data['id'] . ') " value="Delete" /></td>';
                    echo '  </tr> ';
                }
                ?>
            </table>

        </div>
    </center>
</body>

</html>
